﻿using System;
using System.Web.UI.WebControls;
using viBlog.Classes;
using viBlog.Controllers;
using visinia.SmartEngine;

public partial class Admin_Pages_viBlog_Comments_Comment : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["CommentId"] != null)
        {
            int commentId = 0;
            if(Int32.TryParse(Request.QueryString["CommentId"], out commentId))
            {
                Comment comment = CommentController.GetCommentAdmin(commentId);
                if (comment != null)
                {
                    Author.Text = comment.Author;
                    Email.Text = comment.Email;
                    Website.Text = comment.Website;
                    Content.Text = comment.Content;
                    Status.SelectedValue = Convert.ToInt32(comment.Status).ToString();
                }
            }
        }
    }
    protected void SAVE_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["CommentId"] != null)
        {
            int commentId = 0;
            if (Int32.TryParse(Request.QueryString["CommentId"], out commentId))
            {
                Comment comment = CommentController.GetCommentAdmin(commentId);
                if (comment != null)
                {
                    comment.Author = Author.Text;
                    comment.Email = Email.Text;
                    comment.Website = Website.Text;
                    comment.Content = Content.Text;
                    comment.Status = (Comment.CommentStatus) Convert.ToInt32(Status.SelectedValue);
                    CommentController.UpdateComment(comment);
                    Response.Redirect(SystemMenu.CallPage("viBlog", "Comments"));
                }
            }
        }
    }
    protected void CANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.RawUrl);
    }
}